import 'package:WebTest/theme/theme_manager.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());
//1.一旦设置主题，那么应用程序中的某些widget，就会直接使用主题的样式

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
//      theme: ThemeData(
//        /*
//        * primarySwatch传入不是color，而是MaterialColor，包含了primaryColor和accentColor
//        * primaryColor单独设置导航和tabBar的颜色
//        * accentColor单独设置floatingActionButton和Switch的颜色等
//        * */
//          primarySwatch: Colors.lightBlue,
//          primaryTextTheme: TextTheme(headline6: TextStyle(color: Colors.white)),
//          brightness: Brightness.light,
//          buttonTheme: ButtonThemeData(minWidth: 30, height: 30),
//          cardTheme: CardTheme(
//              color: Colors.greenAccent,
//              elevation: 10
//          ),
//          textTheme: TextTheme(
//              bodyText2: TextStyle(fontSize: 30,color: Colors.red),
//            bodyText1: TextStyle(fontSize: 20,color:Colors.green),
//          )
//      ),
      theme: HYMyAppTheme.normalTheme,
      darkTheme: HYMyAppTheme.darkTheme,
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  bool _switch = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Material App Bar'),
      ),
      body: Center(
        child: Container(
          child: Column(
            children: <Widget>[
              Text(
                "Hello world",
                style: Theme.of(context).textTheme.bodyText1,
              ),
              Text(
                "Hello world",
                style: Theme.of(context).textTheme.bodyText2,
              ),
              Switch(
                value: _switch,
                activeColor: Colors.red,
                activeTrackColor: Colors.red,
                inactiveThumbColor: Colors.green,
                inactiveTrackColor: Colors.green,
                onChanged: (value) {
                  setState(() {
                    _switch = value;
                  });
                },
              ),
              CupertinoSwitch(
                value: _switch,
                onChanged: (value) {
                  setState(() {
                    _switch = value;
                  });
                },
              ),
              RaisedButton(
                child: Text("按钮"),
              ),
              ButtonTheme(
                minWidth: 10,
                height: 10,
                buttonColor: Colors.green,
                disabledColor: Colors.purple,
                focusColor: Colors.red,
                hoverColor: Colors.orange,
                child: FlatButton(
//                    color: Colors.green,
                  padding: EdgeInsets.all(10),
                  child: Text("button"),
                  onPressed: () {},
                ),
              ),
              Card(
                child: Text(
                  "你好啊，李银河",
                  style: TextStyle(fontSize: 50),
                ),
              )
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(
          Icons.forward,
          color: Colors.white,
        ),
        onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (context) {
              return HYHomeDetailPage();
            },
          ));
        },
      ),
    );
  }
}

class HYHomeDetailPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(
        primaryColor: Colors.green,
      ),
      child: Scaffold(
        appBar: AppBar(
          title: Text("详情页"),
        ),
        body: Center(
          child: Text(
            "home detail",
            style: Theme.of(context).textTheme.bodyText1,
          ),
        ),
        floatingActionButton: Theme(
          data: Theme.of(context).copyWith(
            colorScheme: Theme.of(context).colorScheme.copyWith(
                  secondary: Colors.purple,
                ),
          ),
          child: FloatingActionButton(
            child: Icon(Icons.people),
            onPressed: () {},
          ),
        ),
      ),
    );
  }
}
